#include "drivers.h"

#define MAX_DRIVER_SIZE 32

/**
 * driver index
 */
static uint32_t indexPermGen = 0;
static uint32_t indexYoungGen = 0;

/**
 * Driver object at permanent generation.
 *
 * The lifecycle of the objects in this array accompanies the entire program
 * execution. This means that these objects will not be reclaimed by the garbage
 * collector during the program's runtime.
 */
static void *driverPermGen[MAX_DRIVER_SIZE];
/**
 * Driver object at young generation
 *
 * These objects typically have a short lifespan in the Young Generation and
 * are frequently subject to garbage collection.
 */
static void *driverYoungGen[MAX_DRIVER_SIZE];


void Driver_add(void *driver, enum ObjectGen objectGen) {
    if (objectGen == GEN_PERM) {
        driverPermGen[indexPermGen++] = driver;
    } else if (objectGen == GEN_YOUNG) {
        driverYoungGen[indexYoungGen++] = driver;
    }
}

 void Driver_free() {
    for (int i = 0; i < indexYoungGen; ++i) {
        free(driverYoungGen[i]);
    }
}

 void Driver_freeAll() {
    Driver_free();

    for (int i = 0; i < indexPermGen; ++i) {
        free(driverPermGen[i]);
    }
}
